//
//  HotListTableViewCell.m
//  WXMusic
//
//  Created by 漫步人生路 on 15/9/1.
//  Copyright (c) 2015年 漫步人生路. All rights reserved.
//

#import "HotListTableViewCell.h"

@implementation HotListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        //歌单图片
        self.songsPic = [[UIImageView alloc]initWithFrame:CGRectMake(10, 15, kWidth /   (375 / 100), kWidth / (375 / 100))];
        
        //歌单名
        self.songsListName = [[UILabel alloc]initWithFrame:CGRectMake(25 + self.songsPic.bounds.size.width, 15, kWidth - self.songsPic.bounds.size.width - 25, 35)];
        //分割线
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(25 + self.songsPic.bounds.size.width, self.songsListName.bounds.size.height + 17, self.songsListName.bounds.size.width - 25, 1)];
        //歌单简介
        self.songsIntroduce = [[UILabel alloc]initWithFrame:CGRectMake(25 + self.songsPic.bounds.size.width, self.songsListName.bounds.size.height + 20, self.songsListName.bounds.size.width - 25, self.songsPic.bounds.size.height - self.songsListName.bounds.size.height - 5)];
        //音符图标
        self.songsIcon = [[UIImageView alloc]initWithFrame:CGRectMake(25 + self.songsPic.bounds.size.width, self.songsPic.bounds.size.height + 15, 20, 20)];
        //听众数
        self.songserCount = [[UILabel alloc]initWithFrame:CGRectMake(40 + self.songsPic.bounds.size.width, self.songsPic.bounds.size.height + 15, 100, 30)];
        
        self.songsPic.backgroundColor = [UIColor whiteColor];
        lineView.backgroundColor = [UIColor whiteColor];
        self.songsIcon.image = [UIImage imageNamed:@"sing_img_note5"];
        UIView *bomLine = [[UIView alloc]initWithFrame:CGRectMake(10, self.songsPic.bounds.size.height + 40, kWidth - 20, 1)];
        bomLine.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:bomLine];
        [self setUpSongsPic:self.songsPic];
        [self setUpSongsListName:self.songsListName];
        [self.contentView addSubview:lineView];
        [self setUpSongsIntroduce:self.songsIntroduce];
        [self.contentView addSubview:self.songsIcon];
        [self setUpSongserCount:self.songserCount];
        
    }
    return self;
}

- (void)setValueWithModel:(HotListModel *)model
{
    //获取歌单图片
    [self.songsPic sd_setImageWithURL:[NSURL URLWithString:model.pic_300]];
    //获取歌单名
    self.songsListName.text = model.title;
    //获取听众数
    self.songserCount.text = model.listenum;
    //获取歌单简介
    //设置NSAttributedString,我们需要使用该参数为给我们的字典设置属性
    NSAttributedString *attributedString = [[NSAttributedString alloc]initWithString:model.desc];
    //设置label的文本
    self.songsIntroduce.attributedText = attributedString;
    //查询我们字符串长度
    NSRange range = NSMakeRange(0, attributedString.length);
    //设置字典属性
    NSDictionary *dic = [attributedString attributesAtIndex:0 effectiveRange:&range];
    CGSize size = CGSizeMake(300, 999);
    //设置我们文本矩形的大小绘制NSStringDrawingUsesLineFragmentOrigin这个参数是说我们的矩形无法完整显示的时候将以...来表示被忽略的部分
    CGSize stringSize = [self.songsIntroduce.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    //使用stringSize来给我们的label设置文本高度
    self.songsIntroduce.frame = CGRectMake(25 + self.songsPic.bounds.size.width, self.songsListName.bounds.size.height + 20, self.songsListName.bounds.size.width - 25, stringSize.height + 20);
}
//设置听众数
- (void)setUpSongserCount:(UILabel *)songserCount
{
    songserCount.textColor = [UIColor whiteColor];
    songserCount.font = [UIFont boldSystemFontOfSize:12.0];
    [self.contentView addSubview:songserCount];
}


//设置歌单详情
- (void)setUpSongsIntroduce:(UILabel *)songsIntroduce
{
    //换行
    songsIntroduce.numberOfLines = 0;
    //文本颜色
    songsIntroduce.textColor = [UIColor whiteColor];
    //设置字体大小
    songsIntroduce.font = [UIFont boldSystemFontOfSize:12.0];
    [self.contentView addSubview:songsIntroduce];
    
}
//设置歌单名
- (void)setUpSongsListName:(UILabel *)songsListName
{
    //设置文本色
    songsListName.textColor = [UIColor whiteColor];
    //设置字体大小
    songsListName.font = [UIFont boldSystemFontOfSize:15.0];
    //设置文本字体居左
    songsListName.textAlignment = NSTextAlignmentLeft;
    
    [self.contentView addSubview:songsListName];
}





//设置歌单图
- (void)setUpSongsPic:(UIImageView *)songsPic
{
    //允许设置
    songsPic.layer.masksToBounds = YES;
    //设置layer宽度
    songsPic.layer.borderWidth = 2;
    //将songsPic设置为圆形
    songsPic.layer.cornerRadius = songsPic.bounds.size.height / 2;
    //设置songsPic的layer边框色
    songsPic.layer.borderColor = [[UIColor whiteColor] CGColor];
    [self.contentView addSubview:songsPic];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
